<template>
   <div class="sub-filter">
     <div class="item">
       <div class="head">品牌:</div>
       <div class="body">
         <a href="javascript:;" v-for="i in subObj.brands" :key="i.id">{{i.name}}</a>
       </div>
     </div>
     <div class="item" v-for="i in subObj.saleProperties" :key="i">
       <div class="head">{{i.name}}:</div>
       <div class="body">
         <a href="javascript:;" v-for="item in i.properties" :key="item.id">{{item.name}}</a>
       </div>
     </div>
   </div>
</template>
<script>
import { findSubCategoryFilter } from '@/api/category'
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'
export default {
  name: 'SubFilter',
  setup () {
    const subObj = ref({})
    const route = useRoute()
    async function getSubObj () {
      const res = await findSubCategoryFilter(route.params.id)
      // 在品牌和规格list的头部添加一个全部类别
      // 处理品牌
      const result = res.result
      result.brands.unshift({
        id: null,
        name: '全部'
      })
      // 类别加全部
      result.saleProperties.forEach(item => {
        item.properties.unshift({
          id: null,
          name: '全部'
        })
      })
      subObj.value = result
    }
    onMounted(() => {
      getSubObj()
    })

    return {
      subObj
    }
  }
}
</script>

<style scoped lang='less'>
  // 筛选区
  .sub-filter {
    background: #fff;
    padding: 25px;
    .item {
      display: flex;
      padding: 10px 0;
      .head {
        width: 80px;
        color: #999;
      }
      .body {
        flex: 1;
        a {
          margin-right: 36px;
          transition: all .3s;
          &.active,
          &:hover {
            color: @xtxColor;
          }
        }
      }
    }
  }
</style>
